<?php

namespace app\common\controller;

use think\Controller;
use think\Request;
use ztouch\ZeroTouch;
use think\facade\Cache;

class Common extends Controller
{
   /**
    * [get_code description]获取验证码
    * @param  [type] $phone [description]
    * @param  string $param [description]默认随机获取验证码，如果有指定方式可以传入
    * @return [type]        [description]
    */
   public function get_code($phone, $ip, $param = '')
   {
   		$ztouch = new ZeroTouch();
    	$res = $ztouch->sendVertifyMsg($phone);
    	if ($res->code == 000000 && $res->msg == 'OK') {
    		$time = Cache::store('redis')->get('ztouch_times_'.$phone) ? Cache::store('redis')->get('ztouch_times_'.$phone) + 1: 1;
    		$expire_time = strtotime(date('Y-m-d 23:59:59', time())) -time();
    		Cache::store('redis')->rm('ztouch_times_'.$phone);
    		Cache::store('redis')->set('ztouch_times_'.$phone, $time, $expire_time); // 当前用户当天获取的次数
    		Cache::store('redis')->set('ztouch_ip_'.$ip, $ip, 60); // 当前访问ip的频繁时间
    		return true;
    	} else {
        dump($res);
    		return false;
    	}
    	
   }
}
